package com.tanhua.server.controller;

import com.tanhua.model.vo.MovementVo;
import com.tanhua.model.vo.MovementsVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.MovementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/movements")
public class MovementController {

    @Autowired
    private MovementService movementService;

    /**
     * 动态-发布
     * @param movementVo
     * @param imageContent
     * @return
     */
    @PostMapping
    public ResponseEntity postMovement(MovementVo movementVo, MultipartFile[] imageContent){
        movementService.postMovement(movementVo,imageContent);
        return ResponseEntity.ok(null);
    }

    /**
     * 分页查询个人动态
     * @return
     */
    @GetMapping("/all")
    public ResponseEntity findByUserId(@RequestParam(value = "page",defaultValue = "1") Long page,
                                       @RequestParam(value = "pageSize",defaultValue = "10") Long pageSize,
                                       Long userId){
        PageResult<MovementsVo> movementVoPageResult = movementService.findByUserId(page,pageSize,userId);
        return ResponseEntity.ok(movementVoPageResult);
    }

    /**
     * 好友动态
     * @return
     */
    @GetMapping
    public ResponseEntity movements(@RequestParam(value = "page",defaultValue = "1") Long page,
                                       @RequestParam(value = "pageSize",defaultValue = "10") Long pageSize){
        PageResult<MovementsVo> movementVoPageResult = movementService.findFriendMovements(page,pageSize);
        return ResponseEntity.ok(movementVoPageResult);
    }

    /**
     * 推荐动态
     * @return
     */
    @GetMapping("/recommend")
    public ResponseEntity recommend(@RequestParam(value = "page",defaultValue = "1") Long page,
                                    @RequestParam(value = "pageSize",defaultValue = "10") Long pageSize){
        PageResult<MovementsVo> movementVoPageResult = movementService.recommend(page,pageSize);
        return ResponseEntity.ok(movementVoPageResult);
    }


    /**
     * 查询单条动态
     * @param movementId
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity findById(@PathVariable("id") String movementId){
        MovementsVo movementsVo = movementService.findById(movementId);
        return ResponseEntity.ok(movementsVo);
    }

    /**
     * 动态点赞
     * @param movementId
     * @return
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String movementId){
        Integer likeCount = movementService.like(movementId);
        return ResponseEntity.ok(likeCount);
    }

    /**
     * 动态喜欢
     * @param movementId
     * @return
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") String movementId){
        Integer loveCount = movementService.love(movementId);
        return ResponseEntity.ok(loveCount);
    }


    /**
     * 动态取消点赞
     * @param movementId
     * @return
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String movementId){
        Integer likeCount = movementService.dislike(movementId);
        return ResponseEntity.ok(likeCount);
    }

    /**
     * 动态喜欢
     * @param movementId
     * @return
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") String movementId){
        Integer loveCount = movementService.unlove(movementId);
        return ResponseEntity.ok(loveCount);
    }

}
